<?php

/*
 * Copyright (C) 2015 ziroom.com
 * 
 * One Page Principle:
 * A specification that will not fit on one page of 8.5x11 inch
 * paper cannot be understood.
 * -- Mark Ardis
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * This program is created by JIAO Jie.
 * The official website is <http://www.ziroom.com/>
 */

namespace Jiaojie\Util\Xml;

/**
 * Simple Xml String Phrse To Array
 * @author JIAO Jie
 * @date 2015-5-7
 * @version 1.0.0
 * @description
 */
class String {

    /**
     * Xml String Content
     * @var string 
     */
    private $content;

    /**
     * Construct Method
     * @param string $content
     * @throws \Jiaojie\Util\Xml\Error
     */
    public function __construct($content) {
        if(empty($content)) {
            throw new Error(Error::EMPTY_ERROR);
        }
        $this->content = $content;
    }
    
    /**
     * Phrse Xml String To Array
     * @return array
     * @throws \Jiaojie\Util\Xml\Error
     */
    public function phrse() {
        $xml = simplexml_load_string($this->content);
        if(empty($xml)) {
            throw new Error(Error::PARSE_ERROR);
        }
        return Tool::xmlElementToArray($xml);
    }

}
